package com.resource.project.service.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resource.project.entity.system.HrRole;
import com.resource.project.entity.system.Role;
import com.resource.project.mapper.HrRoleMapper;
import com.resource.project.service.system.service.IHrRoleService;
import com.resource.project.service.system.service.IRoleService;
import com.resource.project.service.system.service.os.HrRoleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author resource
 * @since 2020-03-14
 */
@Service
public class HrRoleServiceImpl extends ServiceImpl<HrRoleMapper, HrRole> implements IHrRoleService {

    @Autowired
    private IRoleService roleService;
    @Override
    public List<HrRoleDTO> getAllRoleByHrId(Long id) {
        return list(Wrappers.<HrRole>lambdaQuery().eq(HrRole::getHrid,id)).stream().map(t->toDTO(t)).collect(Collectors.toList());
    }

    private HrRoleDTO toDTO(HrRole hrRole) {
        HrRoleDTO dto = new HrRoleDTO();
        Role role = roleService.getById(hrRole.getRid());
        org.springframework.beans.BeanUtils.copyProperties(hrRole,dto);
        dto.setRoleName(role.getName());
        return dto;
    }
}
